<template>
	<div class="box" style="padding: 10px;">
		<div style="width: 100%;height: 92vh;overflow-y: scroll;">
			<van-cell-group>
				<van-field :value="obj.iawName" placeholder="请输入法律名称" :border="true" label="法律名称" type="textarea"
					autosize clickable input-align="left" @change="changeInput($event, 'iawName')" />
					
				<van-field :value="obj.iawIntroduce" placeholder="请输入法律介绍" :border="true" label="法律介绍" type="textarea"
					autosize clickable input-align="left" @change="changeInput($event, 'iawIntroduce')" />
					
				<van-field :value="obj.length" placeholder="请输入法律介绍" :border="true" label="条款条数" type="textarea"
					autosize clickable input-align="left" @change="changeInput($event, 'length')" />
					
				<van-field :value="obj.createTime" readonly placeholder="请输入创建时间" :border="true" label="创建时间" 
					input-align="left" @change="changeInput($event, 'createTime')" />
			</van-cell-group>
		</div>
		
		<div class="btn">
			<button @click="save">保存</button>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				obj: {
					createTime:""
				}
			}
		},
		
		onLoad(option) {
			if(option._id){
				this.getDetail(option._id)
			}
			this.obj.createTime = this.$getTime("yyyy-MM-DD")
		},

		methods: {
			// 输入框发生变化
			changeInput(e, str) {
				this.obj[str] = e.detail;
			},
			
			async getDetail(id){
				let result = await this.$axios('overallSituation', {
					databaseName: 'lawList',
					state: 'look',
					_id:id
				}, true)
				
				if(result.code == 200){
					this.obj = result.data[0] || {}
				}
			},
			
			async save(){
				if(!this.obj.iawName){
					uni.showToast({
						title:"请输入法律名称",
						icon:"none",
						duration:2000
					})
					return
				}
				let result = await this.$axios('overallSituation', {
					databaseName: 'lawList',
					state: this.obj._id ? 'update' : 'add',
					...this.obj
				}, true)
				
				if(result.code == 200){
					uni.showToast({
						title:"添加成功",
						icon:"none",
						duration:2000
					})
					
					uni.navigateBack({
						delta: 1,
					});
				}
			}
		}
	}
</script>

<style scoped>
	.btn {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.btn button {
		width: 96%;
		height: 35px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		font-size: 12px;
		font-weight: 700;
		background: #e53935;
	}
</style>